package com.medvalley.tcm.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.domain.UserInfo;
import com.medvalley.tcm.service.impl.MyMusicService;
import com.medvalley.tcm.service.impl.UserInfoServiceImpl;
import com.medvalley.tcm.vo.outputvo.MyCheckMusicOutputVo;
import com.medvalley.tcm.vo.outputvo.MyMusicOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/my_music")
@Api("我的音乐")
public class MyMusicController extends BaseController {

    @Autowired
    private MyMusicService myMusicService;

    @PostMapping("/add_favorite")
    @ApiOperation("添加到我喜欢")
    public Result addFavorite(@RequestParam int musicId, HttpServletRequest request) {
        myMusicService.addMyMusic(getUserId(request), musicId);
        return success();
    }

    @PostMapping("/remove_favorite")
    @ApiOperation("从我喜欢删除")
    public Result deleteFavorite(@RequestParam int musicId, HttpServletRequest request) {
        myMusicService.deleteFromMyMusic(musicId, getUserId(request));
        return success();
    }

    @PostMapping("/list_favorite")
    @ApiOperation("从我喜欢删除")
    public Result listMyMusic(HttpServletRequest request) {
        List<MyMusicOutputVo> outputVos = myMusicService.listMyMusic(getUserId(request));
        return success(outputVos);
    }

    @PostMapping("/download")
    @ApiOperation("下载音乐")
    public Result downloadMusic(@RequestParam int musicId) {
        //TODO 如何下载
        return success();
    }

    @GetMapping("/recommend")
    @ApiOperation("检测推荐")
    public Result myQuestionSupport(HttpServletRequest request) {
        String sessionPhone = getSessionPhone(request);
        MyCheckMusicOutputVo myCheckMusicOutputVo = myMusicService.recommendMusic(sessionPhone);
        return success(myCheckMusicOutputVo);
    }

}
